﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace WebAddressBook
{
    public partial class SysSetting : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadSysSetting();
            }
        }

        private void LoadSysSetting()
        {
            Adrr.BLL.SysSetting sysSettingBll = new Adrr.BLL.SysSetting();
            DataSet ds = sysSettingBll.GetAllList();
            if (ds.Tables[0].Rows.Count == 1)
            {
                backupAddress.Value = ds.Tables[0].Rows[0]["BackAddress"].ToString();
                DDLBackHZ.SelectedValue = ds.Tables[0].Rows[0]["BackHZ"].ToString();
            }
        }

        protected void BtSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(backupAddress.Value.Trim()))
            {
                LbMessage.Text = "<div class='box box-error'>请填写备份服务器地址！</div>";
                return;
            }

            Adrr.Model.SysSetting sysSettingModel = new Adrr.Model.SysSetting();
            sysSettingModel.BackAddress = backupAddress.Value.Trim();
            sysSettingModel.BackHZ = int.Parse(DDLBackHZ.SelectedValue);

            Adrr.BLL.SysSetting sysSettingBll = new Adrr.BLL.SysSetting();
            //因为备份设置数据库里面只能有一条记录，所以先删掉原来的，再插入一条新设置的记录
            sysSettingBll.DeleteAll();
            if (sysSettingBll.Add(sysSettingModel))
                LbMessage.Text = "<div class='box box-info'>设置成功！</div>";
            else
                LbMessage.Text = "<div class='box box-error'>设置失败！</div>";

        }

    }
}